﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using Model;

namespace BusinessLogic
{
    public class GetCampaignCommand : BaseCommand<List<acm_campaign>>
    {        
        public int _id { get; set; }
        public DateTime _dt;

        public GetCampaignCommand(DateTime EffectiveDate,int seriesId)
        {
            _dt = EffectiveDate;
            _id = seriesId;

            SetQuery("exec ACM_GET_CAMPAIGN @effectiveDate,@seriesId, 0");

            cmd.Parameters.AddWithValue("effectiveDate", _dt);
            cmd.Parameters.AddWithValue("seriesId", _id);
        }

        public GetCampaignCommand(int id)
        {
            _id = id;

            SetQuery("select id,campaign_name,campaign_desc,start_date,end_date,series_id_list,promotion_amount,promotion_note4 from acm_campaign where id=@id");

            cmd.Parameters.AddWithValue("id", _id);
        }

        public override void Command()
        {
            Result = new List<acm_campaign>();
            SqlDataReader dr = cmd.ExecuteReader();
            
            while (dr.Read())
            {
                acm_campaign row = new acm_campaign();
                row.id = GetNullableInt(dr, 0);
                row.campaign_name = GetNullableString(dr, 1);
                row.campaign_desc = GetNullableString(dr, 2);
                row.start_date = GetNullableDateTime(dr, 3);
                row.end_date = GetNullableDateTime(dr, 4);
                row.series_id_list = GetNullableString(dr, 5);
                row.promotion_amount = GetNullableDecimal(dr,6);
                row.promotion_note4 = GetNullableInt(dr, 7);

                Result.Add(row);
            }
        }
    }
}
